package com.example.demo.servlet;

import com.example.demo.bean.NewsBean;
import com.example.demo.dao.NewsDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/newsDetail.html")
public class NewsDetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String newsId = req.getParameter("newsId");
        int id = Integer.parseInt(newsId);
        NewsBean newsBean = (new NewsDao()).getNewsByID(id);
        req.setAttribute("newsBean", newsBean.getNewsTitle());
        req.setAttribute("content", newsBean.getNewsContent());
        req.getRequestDispatcher("/newsDetail.jsp").forward(req, resp);
    }
}
